package com.kmxd.ams.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kmxd.ams.client.system.ISysJobsSvc;
import com.kmxd.ams.core.common.enums.LogLevelEnum;
import com.kmxd.ams.core.common.enums.LogTypeEnum;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import com.kmxd.ams.infra.system.entity.SysJobs;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 定时任务配置 前端控制器
 *
 * @author ZuoLG
 * @since 2022-08-19
 */
@RestController
@Tag(name = "定时任务配置")
@RequestMapping("/system/sysJobs")
@AllArgsConstructor
public class SysJobsCtl {

  private ISysJobsSvc sysJobsService;

  /** 分页查询 */
  @Operation(summary = "分页查询")
  @GetMapping("/selectPage")
  @AutoLog(module = "定时任务配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "分页查询")
  public R<Page<SysJobs>> selectPage(Page reqPage, SysJobs req) {
    return R.success(sysJobsService.selectPage(reqPage, req));
  }

  /** 列表查询 */
  @Operation(summary = "列表查询")
  @GetMapping("/selectList")
  @AutoLog(module = "定时任务配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "列表查询")
  public R<List<SysJobs>> selectList(SysJobs req) {
    return R.success(sysJobsService.selectList(req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("system:sysJobs:add")
  @AutoLog(module = "定时任务配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "新增")
  public R<Void> add(@Validated @RequestBody SysJobs req) {
    sysJobsService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("system:sysJobs:edit")
  @AutoLog(module = "定时任务配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.HIGH, title = "修改")
  public R<Void> edit(@Validated @RequestBody SysJobs req) {
    sysJobsService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("system:sysJobs:remove")
  @AutoLog(
      module = "定时任务配置",
      type = LogTypeEnum.SYSTEM,
      level = LogLevelEnum.HIGH_RISK,
      title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    sysJobsService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "定时任务配置", type = LogTypeEnum.SYSTEM, level = LogLevelEnum.LOW, title = "查看")
  public R<SysJobs> view(@RequestParam Long id) {
    return R.success(sysJobsService.view(id));
  }
}
